package com.b2s.scrumblr.kb.base;

import org.apache.commons.lang3.StringUtils;

/**
 * Created by Administrator on 2016/8/15.
 */
public abstract class HtmlTemplateBase {
    private String header;
    private String body;
    private boolean useHeaderTemplate = true;
    private boolean useBodyTemplate = true;

    public HtmlTemplateBase(){

    }

    public HtmlTemplateBase(String header, String body) {
        this.header = header;
        this.body = body;
    }

    public HtmlTemplateBase(String header, String body, boolean useHeaderTemplate, boolean useBodyTemplate) {
        this.header = header;
        this.body = body;
        this.useHeaderTemplate = useHeaderTemplate;
        this.useBodyTemplate = useBodyTemplate;
    }

    /**
     * html header
     * @return
     */
    public abstract String header();

    /**
     * html body
     * @return
     */
    public abstract String body();

    public String html(){
        StringBuilder sb = new StringBuilder("<!DOCTYPE html> <html>");
        String header = header();
        String body = body();

        if(StringUtils.isNotBlank(header)) sb.append(header);
        if(StringUtils.isNotBlank(body)) sb.append(body);

        sb.append("</html>");
        return sb.toString();
    }

    public String getHeader() {
        return header;
    }

    public void setHeader(String header) {
        this.header = header;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    /**
     * 如果要使用本地之定义模板，那么传入的header将替换模板中的${header}部分
     * 如果不使用模板，直接返回传入的header
     * @return
     */
    public boolean isUseHeaderTemplate() {
        return useHeaderTemplate;
    }

    public void setUseHeaderTemplate(boolean useHeaderTemplate) {
        this.useHeaderTemplate = useHeaderTemplate;
    }

    /**
     * 如果要使用本地之定义模板，那么传入的body将替换模板中的${body}部分
     * 如果不使用模板，直接返回传入的body
     * @return
     */
    public boolean isUseBodyTemplate() {
        return useBodyTemplate;
    }

    public void setUseBodyTemplate(boolean useBodyTemplate) {
        this.useBodyTemplate = useBodyTemplate;
    }
}
